package com.easemob.helpdesk.fragment;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;

import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toolbar;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.easemob.helpdesk.activity.MainActivity;
import com.housekeeperapp.R;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.events.EventBus;
import com.reactnativenavigation.layouts.Layout;
import com.reactnativenavigation.layouts.LayoutFactory;
import com.reactnativenavigation.params.ActivityParams;
import com.reactnativenavigation.utils.ViewUtils;
import com.reactnativenavigation.views.TitleBar;


/**
 * Created by wsj on 2017/11/21.
 */

public class OrderFragment extends Fragment {

    private ActivityParams activityParams;
    private Layout layout;
    private MainActivity attachActivity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        View view = inflater.inflate(R.layout.fragment_container, null);
//        layouts = (RelativeLayout) view;
        attachActivity = ((MainActivity) getActivity());
        if(attachActivity != null){
            activityParams = attachActivity.getCurActParams(0);
            if (activityParams != null) {
                layout = LayoutFactory.create(attachActivity, activityParams);
                //设置背景
                layout.asView().setBackgroundColor(Color.parseColor("#f3f3f3"));

                TitleBar titleBar = layout.getCurrentScreen().getTopBar().getTitleBar();
                // 设置标题
                final View title = titleBar.getTitleView();
                ViewUtils.runOnPreDraw(title, new Runnable() {
                    @Override
                    public void run() {
                        int location = 35;
                        title.setTranslationX(title.getTranslationX() + (-1 * location + ViewUtils.getScreenWidth() / 2 - title.getWidth() / 2));
                    }
                });
                return layout.asView();
            }
        }
        return  new LinearLayout(getActivity());

    }

    @Override
    public void onResume(){
        super.onResume();
//        if (isRemoving() || !NavigationApplication.instance.isReactContextInitialized()) {
//            return;
//        }


    }


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
//        activityParams = ((MainActivity) activity).getCurActParams(0);
//        attachActivity = (MainActivity) activity;

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (layout != null) {
            layout.destroy();
        }

    }
}
